package com.test;

import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import com.entity.User;
import com.mapper.UserXmlMapper;

import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;


@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MybatisXmlJunit {
	 @LocalServerPort
	 private int port;

	 private URL base;

	 @Autowired
	 private TestRestTemplate template;
	 
	 @Autowired
	 private UserXmlMapper userXmlMapper;

	 @Before
	 public void setUp() throws Exception {
	    this.base = new URL("http://localhost:" + port + "/");
	    System.out.println("================================================="+base);
	    //this.base = new URL("http://localhost:8080/");
	 }

	 @Test
	 public void getHello() throws Exception {
		//获取选定的地址页面信息
	    ResponseEntity<String> response = template.getForEntity(base.toString(),
	                String.class);
	    System.out.println("=================================================================="+response.getBody());
	 }
	 
	 @Test
	 public void testInsert() throws Exception{
		 userXmlMapper.insert(new User("1234567890","德玛西亚之力","20"));
		 userXmlMapper.insert(new User("1234567891","德玛西亚之翼","20"));
		 userXmlMapper.insert(new User("1234567892","德玛西亚皇子","20"));
		 
	 }
	
	 //@Test
	 //public void testQuery(){
		 //List<User> list=userXmlMapper.getAll();
		 //User user=userXmlMapper.getOne("1234567890");
		 //JSONObject jsonObject = JSONObject.fromObject(bean);
		 //for(User u:list){
			 //System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++姓名:"+u.getName()+",年纪:"+u.getAge());
		 //}
		 //System.out.println("________________________________________________________姓名:"+user.getName()+",年纪:"+user.getAge());
	 //}
	
	 //@Test
	 //public void testDelete(){
		 //userXmlMapper.delete("1234567890");
	 //}
}
